If instead of deleting a character the "delete" or "backspace" keys give you "~" or similar you should add the following commands into your ~/.inputrc file and restart BASH:
These commands and functions are aimed to make life much easier: you can make a command abbreviation, gather commands ... You just need to type the commands in your shell or/and add this to your ~/.bashrc file:
1. Alias. Alias renames a command.
Examples:
aliasls='ls --color=auto'aliasl='ls --color=auto'# typing l in command line gives the same result as ls --color=auto.aliascb='cd .. ; l'aliasv='vim'aliassshgarching='ssh -i $HOME/.ssh/id_garch username@vip.rzg.mpg.de'
2. Bash functions. Unfortunately one can not pass an argument to aliases. One can do it with functions
Examples:
function c(){cd"$1" ; ls ;}# F.e. typing c ~ gives the same result as cd ~ ; ls ;.
Mind previously declared aliases work under functions.
Smart Bash history search
Everyone who is working under linux/unix machine would like to have a smart history search in the command line like it is realized in Matlab. For example, if you are just press the "up" button then the last typed command will be displayed, but if your first type for example letter "a" and then push "Up" then the last command starting with "a" will appear.
Sounds tempting?
If you are lucky and your default shell is Bash (see change the default shell) then you have to create the file ".inputrc" (or open) in your home directory and put there the following lines:
For those who uses CShell (sign ">" in the command line) - change this horrible thing to the Bash shell (sine $ ). :)
To indicate what is your shell, just look at the last symbol in your terminal: sign ">" - CShell, sign $ - Bash
SSH without password
Please, follow the instructions. I did it once and it required some attempts to make it properly. As soon as you succeed, please, add here the exact instructions.
Here the script which makes the commands described in the above web-page automatically:
usage:
>>1) save the file on your working machine.
>>2) make sure the PATH variable includes the path to the script: PATH variable
>>3) Make the file executable: chmod +x ssh_wo_pwd.sh
>>4) run the script: ssh_wo_pwd.sh login@server
---
NB:
If you system have been upgraded (to ubuntu10 e.g.), you may face a problems accessing you machine form the outside:
ssh neso
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
a0:17:d6:74:86:6d:1a:00:7f:00:bf:19:da:7b:75:cf.
Please contact your system administrator.
Add correct host key in /usr/people/sergiiev/.ssh/known_hosts to get rid of this message.
Offending key in /usr/people/sergiiev/.ssh/known_hosts:31
RSA host key for neso has changed and you have requested strict checking.
Host key verification failed.
My solution: remove in the ~/.ssh/known_hosts all mentioned lines (here - line 31).
After that you host will become unknown, and you can repeat procedure above to make it known...
Make your ls command printing in colors
Your have to add to the Bash "initializations" file .bashrc in your home directory an alias.
Open for editing the .bashrc file, for example type in your command line:
gedit ~/.bashrc
Put this line there:
aliasls='ls --color=auto'
Save, restart bash
Now it should work.
For those who are working with horrible CShell :
1. Change to Bash :)
2. If you insist working with CShell, then these instructions should be valid but you have to modify not .bashrc, but .cshrc instead.
Change the default shell
If you want to have bash as your terminal shell, you could
configure the GNOME terminal correspondingly (Edit->Current Profile,
Title and Command, check Run custom command ...).
Be careful! it may lead to closing the existing terminals, and programs which were run in them (e.g. windows session)
Command line search
Command line
find . |xargsgrep'string'-sl
The -s is for summary and won't display warning messages such as grep: ./directory-name: Is a directory
The -l is for list, so we get just the filename and not all instances of the match displayed in the results.
Additional key: mtimes - for the time of changes in the file (= 1, -1).
Finds all subdirectories of ANY_PATH folder:
find ANY_PATH -type d
Finds all files of ANY_PATH folder:
find ANY_PATH -type f
Finds all files with .log extensionof ANY_PATH folder:
Examples: goes through all subdirectories of InitialData_2 and prints out the subdirectory which does not contain a file with .log extension:
for i in`find InitialData_2/-type d`; doevala=`ls"$i"|grep".log"|wc -l` ; if["$a"-ne"1"] ; thenecho$i ; fi ; done
BASH data processing
The following command line command takes all files with xyz extension form the current directory, skips first 2 lines, skips the first column, and prints the rest (coordinates) into file with the same name but extension "coors":
for i in*.xyz ; doecho$i; fn=${i%.*}; evaltail-n +3"$i"|gawk'{print $2 " " $3 " " $4}'>"$fn".coors ; done
This command takes all files that end with "_input_RISM" from all subdirectories starting from current ("."). Extracts the file name, prints the file name, copies the file to directory "/net/maxwell/people/frolov/distr/RISM_MOL/LastReleaseRismMol/Systems/":
for i in`find . -name*_input_RISM`; dofn=${i##*/}; echo$fn; cp$i/net/maxwell/people/frolov/distr/RISM_MOL/LastReleaseRismMol/Systems/$fn; done
Getting file_name from file with extension (splitting string according to . symbol):
f='file_name.dat'fn=${f%.*}echo$fn
RESULT: file_name
n='/home/usr/bin'fn=${n##*/}echo$fn
RESULT: bin
Skipping the first and the last symbols from string variable:
i='_VAR_'fn=${i:1:$((${#i}-1))};
echo$fn
RESULT: VAR
Comment: ${#i} - number of symbols in i.
$((${#i}-1)) - perform arithmetic operation - result number of symbols -1 minus ,
${i:1:2} - get all symbols with indexes 1 to 2 from var i.
Regular expression: change all symbols "," to "_" in string variable:
fn='1,2-dimethilbuthane'fn=${fn//\,/\_}echo$fn
RESULT: 1_2-dimethilbuthane
Generating a sequence of digits:
for i in`seq110` ; doecho$i ; done
Open access to a folder (file)
The following command line command allows to open access to the files (folders) to other users:
Linux must know
Table of Contents
Table of contents
Delete and backspace keys in terminal
Aliases and command abbreviations
Smart Bash history search
SSH without password
Make your ls command printing in colors
Change the default shell (e.g to bash)
Command line search
BASH data processing
Open access to a folder (file)
Tabs and mouse in vim
Set default PDF viewer to acroread
Python
How to set up PATH variable
Common commands in .bashrc
unzip
Delete and backspace keys in terminal
If instead of deleting a character the "delete" or "backspace" keys give you "~" or similar you should add the following commands into your ~/.inputrc file and restart BASH:
see more in http://www.ibb.net/~anne/keyboard/keyboard.html#Bash.
Aliases and command abbreviations
These commands and functions are aimed to make life much easier: you can make a command abbreviation, gather commands ... You just need to type the commands in your shell or/and add this to your ~/.bashrc file:1. Alias. Alias renames a command.
Examples:
2. Bash functions. Unfortunately one can not pass an argument to aliases. One can do it with functions
Examples:
Mind previously declared aliases work under functions.
Smart Bash history search
Everyone who is working under linux/unix machine would like to have a smart history search in the command line like it is realized in Matlab. For example, if you are just press the "up" button then the last typed command will be displayed, but if your first type for example letter "a" and then push "Up" then the last command starting with "a" will appear.
Sounds tempting?
If you are lucky and your default shell is Bash (see change the default shell) then you have to create the file ".inputrc" (or open) in your home directory and put there the following lines:
Then restart your bash and now it should work.
For those who uses CShell (sign ">" in the command line) - change this horrible thing to the Bash shell (sine $ ). :)
To indicate what is your shell, just look at the last symbol in your terminal: sign ">" - CShell, sign $ - Bash
SSH without password
Please, follow the instructions. I did it once and it required some attempts to make it properly. As soon as you succeed, please, add here the exact instructions.http://www.linuxhorizon.ro/ssh-wo-passw.html
Here the script which makes the commands described in the above web-page automatically:
usage:
>>1) save the file on your working machine.
>>2) make sure the PATH variable includes the path to the script: PATH variable
>>3) Make the file executable: chmod +x ssh_wo_pwd.sh
>>4) run the script: ssh_wo_pwd.sh login@server
---
The general case is described here:
http://linuxproblem.org/art_9.html
In our particular case, we have a common file system, thus these instructions seem to reduce to:
---
NB:
If you system have been upgraded (to ubuntu10 e.g.), you may face a problems accessing you machine form the outside:
ssh nesoMy solution: remove in the ~/.ssh/known_hosts all mentioned lines (here - line 31).
After that you host will become unknown, and you can repeat procedure above to make it known...
Make your ls command printing in colors
Your have to add to the Bash "initializations" file .bashrc in your home directory an alias.
- Open for editing the .bashrc file, for example type in your command line:
gedit ~/.bashrc- Save, restart bash
Now it should work.For those who are working with horrible CShell :
1. Change to Bash :)
2. If you insist working with CShell, then these instructions should be valid but you have to modify not .bashrc, but .cshrc instead.
Change the default shell
If you want to have bash as your terminal shell, you could
configure the GNOME terminal correspondingly (Edit->Current Profile,
Title and Command, check Run custom command ...).
Be careful! it may lead to closing the existing terminals, and programs which were run in them (e.g. windows session)
Command line search
- Command line
The -s is for summary and won't display warning messages such as grep: ./directory-name: Is a directoryThe -l is for list, so we get just the filename and not all instances of the match displayed in the results.
Additional key: mtimes - for the time of changes in the file (= 1, -1).
Finds all subdirectories of ANY_PATH folder:
Finds all files of ANY_PATH folder:
Finds all files with .log extensionof ANY_PATH folder:
See also for find command:
http://www.linux.ie/newusers/beginners-linux-guide/find.php
Examples: goes through all subdirectories of InitialData_2 and prints out the subdirectory which does not contain a file with .log extension:
BASH data processing
The following command line command takes all files with xyz extension form the current directory, skips first 2 lines, skips the first column, and prints the rest (coordinates) into file with the same name but extension "coors":This command takes all files that end with "_input_RISM" from all subdirectories starting from current ("."). Extracts the file name, prints the file name, copies the file to directory "/net/maxwell/people/frolov/distr/RISM_MOL/LastReleaseRismMol/Systems/":
Getting file_name from file with extension (splitting string according to . symbol):
RESULT: file_name
RESULT: bin
Skipping the first and the last symbols from string variable:
RESULT: VAR
Comment: ${#i} - number of symbols in i.
$((${#i}-1)) - perform arithmetic operation - result number of symbols -1 minus ,
${i:1:2} - get all symbols with indexes 1 to 2 from var i.
Regular expression: change all symbols "," to "_" in string variable:
RESULT: 1_2-dimethilbuthane
Generating a sequence of digits:
Open access to a folder (file)
The following command line command allows to open access to the files (folders) to other users:Tabs and mouse in vim
To turn on mouse in vim:
:set mouse=a
To open new tab:
:tabnew
OR
:tabnew filename
How to set up PATH variable
In bash:
example: export PATH=~/scripts:$PATH
Python
- brackets in a line
import restr(" \"Name\" ")
Set default PDF viewer to acroread
In Ubuntu terminal type:xdg-mime default acroread.desktop application/pdCommand commands in .bashrc
Here is an example bashrc file from Frolov:
Unzip
Extract all files of the zip into the /tmp directoryunzip data.zip -d /tmp